﻿using System;
using System.Reflection;
using YArchitech.Temp.Properties;

namespace YArchitech.Temp
{
	public class HYShapeDescription : Attribute
	{
		public HYShapeDescription(string text)
		{
			this.Text = text;
		}

		public static string ToString(Enum en)
		{
			MemberInfo[] member = en.GetType().GetMember(en.ToString());
			if (member != null && member.Length != 0)
			{
				object[] customAttributes = member[0].GetCustomAttributes(typeof(HYShapeDescription), false);
				if (customAttributes != null && customAttributes.Length != 0)
				{
					return ((HYShapeDescription)customAttributes[0]).Text;
				}
			}
			return en.ToString();
		}

		public static HYShapeProfile ToShape(string shapeString)
		{
			HYShapeProfile result = HYShapeProfile.Rectangular;
			if (Enum.TryParse<HYShapeProfile>(shapeString, out result))
			{
				return result;
			}
			if (Resources.Round == shapeString)
			{
				return HYShapeProfile.Round;
			}
			if (Resources.Oval == shapeString)
			{
				return HYShapeProfile.Oval;
			}
			return HYShapeProfile.Rectangular;
		}

		private string Text;
	}
}
